<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowe');

class Admin extends CI_Controller {

    function __construct() { //inisialisasi library dan helper yang perlu di load
        parent::__construct();
        $this->load->helper('form');
        $this->load->library('pagination');
        $this->load->library('parser');
        $this->load->model('all');
        $log = $this->session->all_userdata();
        if (!isset($log) || $log['login'] != TRUE || $log['hak_akses'] != 1) {
            redirect('main');
        }
    }

    function trueLogin() { //cek sudah login
        $log = $this->session->all_userdata();
        if (!isset($log) || $log['login'] != TRUE || $log['hak_akses'] != 1) {
            redirect('main');
        }
    }

    function index() {//halaman utama
        $this->trueLogin();
        redirect('admin/home');
    }

    function home() {
        $data['blog_title'] = 'Home';
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $id = $this->session->all_userdata();
        $username['user'] = $this->all->username($id);
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('the/home', $username);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function social() {
        $this->trueLogin();
        $data['blog_title'] = "Social";
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/social', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function sejarah() {
        $this->trueLogin();
        $data['blog_title'] = "Sejarah";
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        if ($this->all->sejarah()) {
            $data['sejarah'] = $this->all->sejarah();
        } else {
            $data['sejarah'] = array();
        }
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/sejarah', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function sejarah_edit() {
        $this->trueLogin();
        $data['blog_title'] = "Sejarah";
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        if ($this->all->sejarah()) {
            $data['sejarah'] = $this->all->sejarah();
        } else {
            $data['sejarah'] = array();
        }
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/sejarah_edit', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function sejarah_update() {
        $input = array(
            'title' => $this->input->post('title'),
            'data' => $this->input->post('data')
        );
        $this->all->sejarah_update($input);
        redirect('admin/sejarah');
    }

    function prasarana() {
        $this->trueLogin();
        $data['blog_title'] = "Prasarana";
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        if ($this->all->prasarana()) {
            $data['prasarana'] = $this->all->prasarana();
        } else {
            $data['prasarana'] = array();
        }
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/prasarana', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function prasarana_edit() {
        $this->trueLogin();
        $data['blog_title'] = "Prasarana";
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        if ($this->all->prasarana()) {
            $data['prasarana'] = $this->all->prasarana();
        } else {
            $data['prasarana'] = array();
        }
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/prasarana_edit', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function prasarana_update() {
        $input = array(
            'title' => $this->input->post('title'),
            'data' => $this->input->post('data')
        );
        $this->all->prasarana_update($input);
        redirect('admin/prasarana');
    }

    function visi() {
        $this->trueLogin();
        $data['blog_title'] = "Visi";
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        if ($this->all->visi()) {
            $data['visi'] = $this->all->visi();
        } else {
            $data['visi'] = array();
        }
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/visi', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function visi_edit() {
        $this->trueLogin();
        $data['blog_title'] = "Visi dan Misi Edit";
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        if ($this->all->visi()) {
            $data['visi'] = $this->all->visi();
        } else {
            $data['visi'] = array();
        }
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/visi_edit', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function visi_update() {
        $input = array(
            'title' => $this->input->post('title'),
            'data' => $this->input->post('data')
        );
        $this->all->visi_update($input);
        redirect('admin/visi');
    }

    function edit_social() {
        $this->trueLogin();
        $facebook['data'] = $this->input->post('facebook');
        $twitter['data'] = $this->input->post('twitter');
        $this->all->edit_social($facebook, $twitter);
        redirect('admin/social');
    }

    function tahun() {
        $this->trueLogin();
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $data['blog_title'] = 'Tahun Ajaran';
        $config['base_url'] = $this->config->config['base_url'] . '/index.php/admin/tahun/';
        $config['total_rows'] = $this->all->get_thn();
        $config['per_page'] = 5;
        $config['num_links'] = 2;
        $config['full_tag_open'] = '<div class="pagination">';
        $config['full_tag_openclose'] = '</div>';
        $config['first_link'] = 'Awal';
        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active"><a><strong>';
        $config['cur_tag_close'] = '</strong></a></li>';
        $config['last_link'] = 'Akhir';
        $config['last_tag_open'] = '<li>';
        $config['last_tag_close'] = '</li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $config['next_link'] = '&raquo;';
        $config['next_tag_open'] = '<li class="disable">';
        $config['next_tag_close'] = '</li>';
        $config['prev_link'] = '&laquo;';
        $config['prev_tag_open'] = '<li class="disable">';
        $config['prev_tag_close'] = '</li>';
        $config['uri'] = $this->uri->segment(3);
        $this->pagination->initialize($config);
        if ($this->all->tahun($config)) {
            $tahun['thn'] = $this->all->tahun($config);
        } else {
            $tahun['thn'] = array();
        }
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/tahun_ajaran');
        $this->load->view('admins/tahun_table', $tahun);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function add_thn() {
        $this->trueLogin();
        $input = array(
            'thn' => $this->input->post('thn')
        );
        $this->all->add_thn($input);
        redirect('admin/tahun');
    }

    function ubah_thn() {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        $data['thn'] = $this->all->get_id_thn($id);
        $data['blog_title'] = 'SMP Negeri 1 Sanggau Ledo';
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/tahun_ubah', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function upd_thn() {
        $data = array(
            'id' => $this->input->post('id'),
            'thn' => $this->input->post('thn')
        );
        $this->all->upd_thn($data);
        redirect('admin/tahun');
    }

    function del_thn() {
        $this->trueLogin();
        $dwe = $this->uri->segment(3);
        $this->all->del_thn($dwe);
        redirect('admin/tahun');
    }

    function semester() {
        $this->trueLogin();
        $data['blog_title'] = 'Semester';
        $config['base_url'] = $this->config->config['base_url'] . '/index.php/admin/semester/';
        $config['total_rows'] = $this->all->con_smstr();
        $config['per_page'] = 5;
        $config['num_links'] = 2;
        $config['full_tag_open'] = '<div class="pagination">';
        $config['full_tag_openclose'] = '</div>';
        $config['first_link'] = 'Awal';
        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active"><a><strong>';
        $config['cur_tag_close'] = '</strong></a></li>';
        $config['last_link'] = 'Akhir';
        $config['last_tag_open'] = '<li>';
        $config['last_tag_close'] = '</li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $config['next_link'] = '&raquo;';
        $config['next_tag_open'] = '<li class="disable">';
        $config['next_tag_close'] = '</li>';
        $config['prev_link'] = '&laquo;';
        $config['prev_tag_open'] = '<li class="disable">';
        $config['prev_tag_close'] = '</li>';
        $config['uri'] = $this->uri->segment(3);
        $this->pagination->initialize($config);
        if ($this->all->semester($config)) {
            $smstr['semester'] = $this->all->semester($config);
        } else {
            $smstr['semester'] = array();
        }
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/smstr_add');
        $this->load->view('admins/smstr_table', $smstr);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function add_semester() {
        $this->trueLogin();
        $input = array(
            'semester' => $this->input->post('data'),
        );
        $this->all->add_semester($input);
        redirect('admin/semester');
    }

    function ubah_semester() {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        $data['smstr'] = $this->all->get_id_semester($id);
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $data['blog_title'] = 'SMP Negeri 1 Sanggau Ledo';
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/smstr_ubah', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function upd_semester() {
        $semestr = array(
            'id' => $this->input->post('id'),
            'semester' => $this->input->post('data'),
        );
        $this->all->upd_semester($semestr);
        redirect('admin/semester');
    }

    function del_semester($id) {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        $this->all->del_semester($id);
        $this->semester();
    }

    function hari() {
        $this->trueLogin();
        $data['blog_title'] = 'Hari';
        if ($this->all->hari()) {
            $day['hari'] = $this->all->hari();
        } else {
            $day['hari'] = array();
        }
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/hari_add');
        $this->load->view('admins/hari_table', $day);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function add_hari() {
        $this->trueLogin();
        $input = array(
            'hari' => $this->input->post('hari')
        );
        $this->all->add_hari($input);
        redirect('admin/hari');
    }

    function ubah_hari() {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        $data['hari'] = $this->all->get_id_hari($id);
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $data['blog_title'] = 'Edit Hari';
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/hari_ubah', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function upd_hari() {
        $hr = array(
            'id' => $this->input->post('id'),
            'hari' => $this->input->post('data'),
        );
        $this->all->upd_hari($hr);
        redirect('admin/hari');
    }

    function del_hari() {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        $this->all->del_hari($id);
        redirect('admin/hari');
    }

    function del_akses($id) {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        $this->all->del_akses($id);
        redirect('admin/tahun');
    }

    function jampel() {
        $this->trueLogin();
        if ($this->all->jampel()) {
            $data['jampel'] = $this->all->jampel();
        } else {
            $data['jampel'] = array();
        }
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $data['blog_title'] = 'Jam Pelajaran';
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/jampel_add');
        $this->load->view('admins/jampel_table', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function add_jampel() {
        $this->trueLogin();
        $input = array(
            'jam_ke' => $this->input->post('jam'),
            'mulai' => $this->input->post('mulai'),
            'selesai' => $this->input->post('selesai')
        );
        $this->all->add_jampel($input);
        redirect('admin/jampel');
    }

    function ubah_jampel() {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        $this->all->get_id_jam($id);
        $data['jampel'] = $this->all->jampel();
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $data['blog_title'] = 'Jam Pelajaran';
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/jampel_ubah', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function upd_jampel() {
        $jmp = array(
            'id' => $this->uri->segment(3),
            'jam_ke' => $this->input->post('jam_ke'),
            'mulai' => $this->input->post('mulai'),
            'selesai' => $this->input->post('selesai')
        );
        $this->all->upd_jam($jmp);
        redirect('admin/jampel');
    }

    function del_jampel($id) {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        $this->all->del_jam($id);
        redirect('admin/jampel');
    }

    function kelas() {
        $this->trueLogin();
        if ($this->all->kelas()) {
            $data['kelas'] = $this->all->kelas();
        } else {
            $data['kelas'] = array();
        }
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $data['blog_title'] = 'Kelas';
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/kelas_add');
        $this->load->view('admins/kelas_table', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function add_kelas() {
        $this->trueLogin();
        $input = array(
            'kelas' => $this->input->post('kelas'),
        );
        $this->all->add_kelas($input);
        redirect('admin/kelas');
    }

    function ubah_kelas() {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        if ($this->all->get_id_kelas($id)) {
            $data['kelas'] = $this->all->get_id_kelas($id);
        } else {
            $data['kelas'] = array();
        }
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $data['blog_title'] = 'Kelas';
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/kelas_ubah', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function upd_kelas() {
        $input = array(
            'id' => $this->input->post('id'),
            'kelas' => $this->input->post('kelas')
        );
        $this->all->upd_kelas($input);
        redirect('admin/kelas');
    }

    function del_kelas($id) {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        $this->all->del_kelas($id);
        redirect('admin/kelas');
    }

    function mapel() {
        $this->trueLogin();
        if ($this->all->mapel()) {
            $data['mapel'] = $this->all->mapel();
        } else {
            $data['mapel'] = array();
        }
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $data['blog_title'] = 'Mata Pelajaran';
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/mapel_add');
        $this->load->view('admins/mapel_table', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function add_mapel() {
        $this->trueLogin();
        $input = array(
            'mapel' => $this->input->post('mapel')
        );
        $this->all->add_mapel($input);
        redirect('admin/mapel');
    }

    function ubah_mapel() {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        if ($this->all->get_id_mapel($id)) {
            $data['mapel'] = $this->all->get_id_mapel($id);
        } else {
            $data['mapel'] = array();
        }
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $data['blog_title'] = 'Mata Pelajaran';
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/mapel_ubah', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function upd_mapel() {
        $input = array(
            'id' => $this->input->post('id'),
            'mapel' => $this->input->post('mapel'),
        );
        $this->all->upd_mapel($input);
        redirect('admin/mapel');
    }

    function del_mapel($id) {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        $this->all->del_mapel($id);
        $this->mapel();
    }

    function jadwal() {
        $this->trueLogin();
        if ($this->all->jadwal()) {
            $jdwl['jadwal'] = $this->all->jadwal();
        } else {
            $jdwl['jadwal'] = array();
        }
        $this->load->view('admin/top');
        $this->load->view('admin/nav');
        $this->load->view('admin/slider');
        $this->load->view('admin/sidebar-left-open');
        $this->load->view('admin/menu');
        $this->load->view('admin/sidebar-left-close');
        $this->load->view('admin/mainban-jadwal');
        $this->load->view('admin/jadwal_input');
        $this->load->view('admin/jadwal_table', $jdwl);
        $this->load->view('admin/main-close');
        $this->load->view('admin/bottom');
    }

    function add_jadwal() {
        $this->trueLogin();
        $input = array(
            'hari_id' => $this->input->post('hari'),
            'jam_id' => $this->input->post('jam'),
            'mapel_id' => $this->input->post('mapel'),
            'user_id' => $this->input->post('user'),
            'smstr_id' => $this->input->post('smstr'),
            'thn_ajaran_id' => $this->input->post('thn')
        );
        $this->all->add_jadwal($input);
        redirect('admin/jadwal');
    }

    function del_jadwal($id) {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        $this->all->del_jadwal($id);
        $this->jadwal();
    }

    function user() {
        $this->trueLogin();
        if ($this->all->user()) {
            $data['user'] = $this->all->user();
        } else {
            $data['user'] = array();
        }
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $data['blog_title'] = 'User List';
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/user_table', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function add_user() {
        $this->trueLogin();
        if ($this->all->get_tahun()) {
            $data['tahun'] = $this->all->get_tahun();
        } else {
            $data['tahun'] = array();
        }
        $data['blog_title'] = 'User Add';
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/user_add', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function add_staff() {
        $this->trueLogin();
        $input = array(
            'password' => $this->encrypt->sha1($this->input->post('nama')),
            'akses_id' => 4,
            'nama' => $this->input->post('nama'),
            'email' => $this->input->post('email'),
            'phone' => $this->input->post('telp'),
            'kelas_id' => 1,
            'thn_id' => $this->input->post('tahun'),
            'tmpt_lahir' => $this->input->post('tmpt_lahir'),
            'tgl_lahir' => $this->input->post('tgl_lahir'),
            'sex' => $this->input->post('sex')
        );
        $this->all->add_user($input);
        redirect('admin/user');
    }

    function del_user() {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        $this->all->del_user($id);
        redirect('admin/user');
    }

    function ubah_user() {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        $data['user'] = $this->all->get_user_id($id);
        if ($this->all->get_privilege()) {
            $data['akses'] = $this->all->get_privilege();
        } else {
            $data['akses'] = array();
        }
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $data['blog_title'] = 'User Edit';
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/user_ubah', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function del_usr() {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        $this->all->del_user_id($id);
        redirect('admin/user');
    }

    function upd_usr() {
        $user = array(
            'id' => $this->input->post('user'),
            'nama' => $this->input->post('nama'),
            'sex' => $this->input->post('jenis_kelamin'),
            'akses_id' => $this->input->post('hak_akses'),
            'email' => $this->input->post('mail'),
            'phone' => $this->input->post('telephone'),
            'kelas_id' => $this->input->post('kelas'),
            'thn_id' => $this->input->post('bekerja'),
            'tmpt_lahir' => $this->input->post('tempat_lahir'),
            'tgl_lahir' => $this->input->post('tanggal_lahir')
//            'foto' => $this->input->post('ft_identitas'),
        );
//        echo '<pre>';
//        print_r($hr);
//        echo '</pre>';
        $this->all->upd_user($user);
        redirect('admin/user');
    }

    function privilege() {
        $this->trueLogin();
        if ($this->all->get_privilege()) {
            $data['akses'] = $this->all->get_privilege();
        } else {
            $data['akses'] = array();
        }
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $data['blog_title'] = 'Kelas';
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/akses_add');
        $this->load->view('admins/akses_table', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function add_privilege() {
        $this->trueLogin();
        $input = array(
            'akses' => $this->input->post('akses')
        );
        $this->all->add_privilege($input);
        redirect('admin/privilege');
    }

    function del_privilege() {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        $this->all->del_privilege($id);
        redirect('admin/privilege');
    }

    function ubah_privilege() {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        $data['akses'] = $this->all->get_privilege_id($id);
        $data['blog_title'] = 'Edit Hak Akses';
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/akses_ubah', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function upd_privilege() {
        $this->trueLogin();
        $input = array(
            'id' => $this->input->post('id'),
            'akses' => $this->input->post('akses')
        );
        $this->all->upd_privilege($input);
        redirect('admin/privilege');
    }

    function berita() {
        $this->trueLogin();
        $data['blog_title'] = 'Berita';
        $config['base_url'] = $this->config->config['base_url'] . '/index.php/admin/berita/';
        $config['total_rows'] = $this->all->get_berita();
        $config['per_page'] = 5;
        $config['num_links'] = 2;
        $config['full_tag_open'] = '<div class="pagination">';
        $config['full_tag_openclose'] = '</div>';
        $config['first_link'] = 'Awal';
        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active"><a><strong>';
        $config['cur_tag_close'] = '</strong></a></li>';
        $config['last_link'] = 'Akhir';
        $config['last_tag_open'] = '<li>';
        $config['last_tag_close'] = '</li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $config['next_link'] = '&raquo;';
        $config['next_tag_open'] = '<li class="disable">';
        $config['next_tag_close'] = '</li>';
        $config['prev_link'] = '&laquo;';
        $config['prev_tag_open'] = '<li class="disable">';
        $config['prev_tag_close'] = '</li>';
        $config['uri'] = $this->uri->segment(3);
        $this->pagination->initialize($config);
        if ($this->all->berita($config)) {
            $data['berita'] = $this->all->berita($config);
        } else {
            $data['berita'] = array();
        }
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/berita');
        $this->load->view('admins/berita_table', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function add_berita() {
        $this->trueLogin();
        $input = array(
            'judul' => $this->input->post('judul'),
            'isi' => $this->input->post('berita'),
            'user_id' => $this->session->userdata('id')
        );
        $this->all->add_berita($input);
        redirect('admin/berita');
    }

    function del_berita($id) {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        $this->all->del_news($id);
        redirect('admin/berita');
    }

    function ubah_berita() {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        $data['blog_title'] = 'Update Berita';
        $data['berita'] = $this->all->get_id_news($id);
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/berita_update', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function update_berita() {
        $this->trueLogin();
        $update = array(
            'id' => $this->uri->segment(3),
            'judul' => $this->input->post('judul'),
            'isi' => $this->input->post('berita')
        );
        $this->all->upd_news($update);
        redirect('admin/berita');
    }

    function berita_detail() {
        $this->trueLogin();
        $id = $this->uri->segment(3);
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $data['blog_title'] = 'Detail Berita';
        $data['berita'] = $this->all->berita_detail($id);
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/berita_detail', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function psb() {
        $this->trueLogin();
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $data['blog_title'] = 'Data PSB';
        $data['psb'] = $this->all->psb();
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/psb_table', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function ubah_psb() {
        $this->trueLogin();
        $data['blog_title'] = 'Ubah Data PSB';
        $id = $this->uri->segment(3);
        $data['psb'] = $this->all->get_psb_id($id);
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('admins/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('admins/psb_ubah', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function psb_status() {
        $this->trueLogin();
        $input = array(
            'id' => $this->input->post('id'),
            'status' => $this->input->post('status')
        );
        $this->all->psb_status($input);
        redirect('admin/psb');
    }

    function logout() { //logout
        $this->session->sess_destroy();
        redirect();
    }
}